package com.seh.contentcenter.controller;

import com.seh.contentcenter.domain.Result;
import com.seh.contentcenter.dto.DeliverDTO;
import com.seh.contentcenter.entity.Deliver;
import com.seh.contentcenter.service.Impl.DeliverServiceImpl;
import com.seh.contentcenter.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/deliver")
public class DeliverController {
    @Autowired
    private DeliverServiceImpl deliverService;

    /**
     * 查询所有外送订单信息
     *
     * @return
     */
    @GetMapping("/findAllDeliverInfo/{pageIndex}")
    public Result<List<DeliverDTO>> findAllDeliverInfo(@PathVariable Integer pageIndex) {
        return ResultUtil.deliverInfo(deliverService.findAllDeliverInfo(pageIndex));
    }

    /**
     * 查看订单详细信息
     *
     * @param deliverId
     * @return
     */
    @GetMapping("/selectOneById/{deliverId}")
    public Result<DeliverDTO> selectOneById(@PathVariable Integer deliverId) {
        DeliverDTO deliverDTO = deliverService.selectOneById(deliverId);
        return ResultUtil.deliverInfo(deliverDTO);
    }

    /**
     * 新增代取订单
     *
     * @param deliver
     * @return
     */
    @PostMapping("/addNewDeliver")
    public String addNewDeliver(@RequestBody Deliver deliver) {
        String s = deliverService.addNewDeliver(deliver);
        return s;
    }

    /**
     * 逻辑删除
     *
     * @param deliverId
     * @return
     */
    @GetMapping("/deleteDeliver/{deliverId}")
    public String deleteDeliver(@PathVariable Integer deliverId) {
        String s = deliverService.deleteDeliver(deliverId);
        return s;
    }

    /**
     * 用户中心：查看发布的跑腿信息
     *
     * @param issuerId
     * @return
     */
    @GetMapping("/findAllDeliverByUserId")
    public Result<List<DeliverDTO>> findAllDeliverByUserId(@RequestParam("issuerId") Integer issuerId,
                                                           @RequestParam("pageIndex") Integer pageIndex) {
        return ResultUtil.deliverInfo(deliverService.findAllDeliverByUserId(issuerId, pageIndex));
    }

    /**
     * 根据宿舍园区和快递地址查询订单
     *
     * @param addressName
     * @param receiveName
     * @param price
     * @param publishTime
     * @return
     */
    @GetMapping("/findAllDeliverByAddress")
    public Result<List<DeliverDTO>> findAllDeliverByAddress(@RequestParam("addressName") String addressName,
                                                            @RequestParam("receiveName") String receiveName,
                                                            @RequestParam("price") String price,
                                                            @RequestParam("publishTime") String publishTime,
                                                            @RequestParam("pageIndex") Integer pageIndex) {
        return ResultUtil.deliverInfo(deliverService.findAllDeliverByAddress(addressName, receiveName, price, publishTime, pageIndex));
    }

    /**
     * 用户中心：查看我代取的跑腿信息
     * @param userId
     * @param pageIndex
     * @return
     */
    @GetMapping("/findAllDeliverUserDo")
    public Result<List<DeliverDTO>> findAllDeliverUserDo(@RequestParam("userId") Integer userId,
                                                         @RequestParam("pageIndex") Integer pageIndex) {
        return ResultUtil.deliverInfo(deliverService.findAllDeliverUserDo(userId, pageIndex));
    }

    /**
     *  用户中心：查看我被代取的跑腿信息
     * @param issuerId
     * @param pageIndex
     * @return
     */
    @GetMapping("/findAllDeliverUserBy")
    public Result<List<DeliverDTO>> findAllDeliverUserBy(@RequestParam("issuerId") Integer issuerId,
                                                         @RequestParam("pageIndex") Integer pageIndex) {
        return ResultUtil.deliverInfo(deliverService.findAllDeliverUserBy(issuerId, pageIndex));
    }

    /**
     * 用户代取某一跑腿
     * @param deliverId
     * @param userId
     * @return
     */
    @PostMapping("/updateDeliver")
    public String updateDeliver(@RequestParam("deliverId") Integer deliverId,
                                @RequestParam("userId") Integer userId) {
        return deliverService.updateDeliver(deliverId, userId);
    }

    /**
     * 确认跑腿完成
     * @param deliverId
     * @return
     */
    @GetMapping("/updateDeliverDone/{deliverId}")
    public String updateDeliverDone(@PathVariable Integer deliverId) {
        return deliverService.updateDeliverDone(deliverId);
    }
}
